package com.ruoyi.zhgd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.ruoyi.zhgd.util.PageUtils;
import com.ruoyi.zhgd.util.Query;
import com.ruoyi.zhgd.dto.AsphaltRequiresDto;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.NLaboratoryAsphaltRequiresRefVo;
import com.ruoyi.zhgd.domain.bo.NLaboratoryAsphaltRequiresRefBo;
import com.ruoyi.zhgd.service.INLaboratoryAsphaltRequiresRefService;

/**
 * 沥青技术要求_列表
 *
 * @author cj
 * @date 2023-09-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/laboratoryAsphaltRequiresRef")
public class NLaboratoryAsphaltRequiresRefController extends BaseController {

    private final INLaboratoryAsphaltRequiresRefService iNLaboratoryAsphaltRequiresRefService;

    /**
     * 查询沥青技术要求_列表列表
     */
/*    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<NLaboratoryAsphaltRequiresRefVo> list(NLaboratoryAsphaltRequiresRefBo bo, PageQuery pageQuery) {
        return iNLaboratoryAsphaltRequiresRefService.queryPageList(bo, pageQuery);
    }*/

    /**
     * 导出沥青技术要求_列表列表
     */
    @SaCheckLogin
    @Log(title = "沥青技术要求_列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(NLaboratoryAsphaltRequiresRefBo bo, HttpServletResponse response) {
        List<NLaboratoryAsphaltRequiresRefVo> list = iNLaboratoryAsphaltRequiresRefService.queryList(bo);
        ExcelUtil.exportExcel(list, "沥青技术要求_列表", NLaboratoryAsphaltRequiresRefVo.class, response);
    }

    /**
     * 获取沥青技术要求_列表详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<NLaboratoryAsphaltRequiresRefVo> getInfo(@NotNull(message = "主键不能为空")
                                                      @PathVariable String id) {
        return R.ok(iNLaboratoryAsphaltRequiresRefService.queryById(id));
    }

    /**
     * 新增沥青技术要求_列表
     */
    @SaCheckLogin
    @Log(title = "沥青技术要求_列表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody NLaboratoryAsphaltRequiresRefBo bo) {
        return toAjax(iNLaboratoryAsphaltRequiresRefService.insertByBo(bo));
    }


    /**
     * 修改沥青技术要求_列表
     */
    @SaCheckLogin
    @Log(title = "沥青技术要求_列表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody NLaboratoryAsphaltRequiresRefBo bo) {
        return toAjax(iNLaboratoryAsphaltRequiresRefService.updateByBo(bo));
    }

    /**
     * 删除沥青技术要求_列表
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "沥青技术要求_列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iNLaboratoryAsphaltRequiresRefService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
    * 沥青类技术要求分页列表
    * @author cj
    * @date 2023/9/21 15:18
    * @return
    **/
    @SaCheckLogin
    @GetMapping("/page")
    public R page(@RequestParam Map<String, Object> params,
                  @RequestParam(value = "pageNum", required = false) Integer pageNum,
                  @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", pageNum);
        paramMap.put("limit", pageSize);
        PageUtils pageUtils = iNLaboratoryAsphaltRequiresRefService.queryPage(new Query(paramMap).getPage(), params);
        return R.ok(pageUtils);
    }


    /**
     * 沥青类技术要求详情
     * @return
     * @author cj
     * @date 2023/9/21 15:17
     **/
    @SaCheckLogin
    @GetMapping("/detail")
    public R detail(@RequestParam(value = "id", required = false) String id) {
        AsphaltRequiresDto dto = iNLaboratoryAsphaltRequiresRefService.detail(id);
        return R.ok(dto);
    }

}
